package com.ewhale.feitengguest.presenter.shop.task

import com.ewhale.feitengguest.api.ApiHelper
import com.ewhale.feitengguest.dto.EditTaskDto
import com.ewhale.feitengguest.dto.ShopTaskDto
import com.ewhale.feitengguest.dto.WaitHandleDto
import com.ewhale.feitengguest.view.shop.task.STaskView
import com.simga.library.base.IPresenter
import com.simga.library.http.APIException

/**
 * 作者：SimGa
 * 日期：2020/1/2
 * 时间：11:17
 * 包名：com.ewhale.feitengguest.presenter.shop.task
 */
class STaskPresenter : IPresenter() {
    fun loadTaskList(pageNumber: Int, status: Int) {
        request(1, ApiHelper.TASK_API.getShopTaskList(pageNumber, 10, status), null)
    }

    fun loadTaskEditDetail(id: Long) {
        mView.showProLoading()
        request(2, ApiHelper.TASK_API.editMission(id), null)
    }

    fun deleteTask(id: Long, it: Int) {
        mView.showProLoading()
        request(3, ApiHelper.TASK_API.deleteMission(id), it)
    }

    fun suspendTask(id: Long, it: Int) {
        mView.showProLoading()
        request(4, ApiHelper.TASK_API.updateMissionStopStatus(id, 1), it)
    }

    fun startTask(id: Long, it: Int) {
        mView.showProLoading()
        request(5, ApiHelper.TASK_API.updateMissionStopStatus(id, 0), it)
    }
    fun endTask(id: Long, it: Int) {
        mView.showProLoading()
        request(6, ApiHelper.TASK_API.overMission(id), it)
    }
    override fun <T : Any?> onNext(postCode: Int, result: T, data: Any?) {
        super.onNext(postCode, result, data)
        when (postCode) {
            1 -> (mView as STaskView).showTaskList(result as List<ShopTaskDto>)
            2 -> (mView as STaskView).showEditDetail(result as EditTaskDto)
            3 -> (mView as STaskView).deleteSuccess(data as Int)
            4 -> (mView as STaskView).suspendSuccess(data as Int)
            5 -> (mView as STaskView).startSuccess(data as Int)
            6 -> (mView as STaskView).endSuccess(data as Int)
        }
    }

    override fun otherException(postCode: Int, data: Any?, e: APIException?) {
        super.otherException(postCode, data, e)
        mView.showErrorMessage(postCode, e!!.code, e.displayMessage)
    }


}
